package com.example.base.net

import com.example.base.entity.AddCarEntity
import com.example.base.entity.CarEntity
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CodeSendEntity
import com.example.base.entity.CouponEntity
import com.example.base.entity.CreateOrderEntity
import com.example.base.entity.GetPreOrderEntity
import com.example.base.entity.GoodsEntity
import com.example.base.entity.IndexEntity
import com.example.base.entity.LoginEntity
import com.example.base.entity.OrderEntity
import com.example.base.entity.PayResultEntity
import com.example.base.entity.PreOrderEntity
import com.example.base.entity.Res
import com.example.base.entity.UploadEntity
import com.example.base.entity.UserInfoEntity
import com.example.base.entity.XqEntity
import com.example.base.param.PCreateOrder
import com.example.base.param.PPay
import com.example.base.param.PPreOrder
import com.example.base.param.PRefund
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query


interface ApiService {

    //我们需要用协程方式来请求数据   挂起函数可以被协程调用
    @POST(Cons.CODE_SEND_URL)
    suspend fun codeSend(@Query("phone") phone: String): Res<CodeSendEntity>

    //验证码登录
    @POST(Cons.LOGIN_CODE_URL)
    suspend fun loginCode(@Body body: RequestBody): Res<LoginEntity>

    //用户信息
    @GET(Cons.UER_INFO_URL)
    suspend fun userInfo(): Res<UserInfoEntity>

    //修改密码
    @POST(Cons.UPDATE_PWD_URL)
    suspend fun updatePwd(@Body body: RequestBody): Res<Boolean>

    //首页数据
    @GET(Cons.INDEX_URL)
    suspend fun index(): Res<IndexEntity>

    @GET(Cons.INDEX_GOODS_URL)
    suspend fun indexGoods(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): Res<GoodsEntity>

    //优惠券列表
    @GET(Cons.COUPON_URL)
    suspend fun coupon(
        @Query("limit") limit: String,
        @Query("page") page: String,
        @Query("type") type: String
    ): Res<CouponEntity>
    //领取优惠券
    @POST(Cons.COUPON_RECEIVE_URL)
    suspend fun couponReceive(@Body body: RequestBody):Res<String?>
    //请求商品列表
    @GET(Cons.GOODS_URL)
    suspend fun goods(@Query("cid")cid:Int,
                      @Query("keyword")keyword:String,
                      @Query("limit")limit:Int,
                      @Query("news")news:Boolean,
                      @Query("page")page:Int,
                      @Query("priceOrder")priceOrder:String,
                      @Query("salesOrder")salesOrder:String
                      ):Res<GoodsEntity>
    //查看详情
    @GET(Cons.XQ_URL)
    suspend fun xq(@Path("id")id:Int,@Query("type")type:String):Res<XqEntity>
    //添加购物车
    @POST(Cons.ADD_CAR_URL)
    suspend fun addCar(@Body body: RequestBody):Res<AddCarEntity>
    //购物车列表
    @GET(Cons.CAR_URL)
    suspend fun car(@Query("isValid")isValid:String,@Query("limit")limit:String,@Query("page")page:String):Res<CarEntity>
    @POST(Cons.UPDATE_CAR_URL)
    suspend fun updateCar(@Query("id")id:Int,@Query("number")number:Int):Res<String?>
    @POST(Cons.DELETE_CAR_URL)
    suspend fun deleteCar(@Query("ids")ids:Array<Int>):Res<String?>
    @GET(Cons.CATEGORY_URL)
    suspend fun category():Res<CategoryEntity>
    //预下单
    @POST(Cons.PREORDER_URL)
    suspend fun preOrder(@Body pPreOrder: PPreOrder):Res<PreOrderEntity>
    @GET(Cons.GET_PREODER_URL)
    suspend fun getPreOrder(@Path("preOrderNo")preOrderNo:String):Res<GetPreOrderEntity>
    @POST(Cons.CREATE_ORDER_URL)
    suspend fun createOrder(@Body pCreateOrder: PCreateOrder):Res<CreateOrderEntity>
    @POST(Cons.PAY_URL)
    suspend fun pay(@Body pPay: PPay):Res<PayResultEntity>
    @Multipart
    @POST(Cons.UPLOAD_URL)
    suspend fun upload(@Query("model")model:String,@Part part: MultipartBody.Part,@Query("pid")pid:String):Res<UploadEntity>
    @GET(Cons.ORDER_URL)
    suspend fun order(@Query("type")type:String,@Query("limit")limit:Int,@Query("page")page:Int):Res<OrderEntity>
    @POST(Cons.REFUND_URL)
    suspend fun refund(@Body pRefund: PRefund):Res<String?>

}